package org.ocelot.tunes4j.dao;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.SqlMapperException;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class IbatisSQLSessionUtil {

	public static final String RESOURCE_PATH = "resources/Configuration.xml";
	public static SqlSessionFactory sqlMapper = null;
	
	public static SqlSessionFactory getSQLSessionFactory() {
		try {
			if(sqlMapper==null) {
				Reader reader = Resources.getResourceAsReader(RESOURCE_PATH);
				sqlMapper = new SqlSessionFactoryBuilder().build(reader);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sqlMapper;
	}
}
